/*
 * ControlLayer.h
 *
 *  Created on: 2010-9-12
 *      Author: try
 */

#ifndef CONTROLLAYER_H_
#define CONTROLLAYER_H_

#include "SimpleButton.h"
#include "../../commons.h"
#include "../../gdiplus/gdraw.h"
#include "WorkLayer.h"

using namespace std;
using namespace Thk;
using namespace Ed;

namespace S{
  class WorkPage;
//  class WorkLayer;

  class ControlLayer: public Layer {
    public:
      ControlLayer(WorkPage* page, WorkLayer* workLayer);
      virtual ~ControlLayer();

      SimpleButton& ControlLayer::addButton(int id, const wchar_t* filename);

    protected:
//      void mouseMoveEvent(const MouseEvent* e);

      void mouseEnterEvent(const MouseEvent* e);
      void mouseLeaveEvent(const MouseEvent* e);

    private:

      /**
       * 控制层操作按钮监听器（移动选中元素到顶层）
       */
      class ToTopButtonListener : public EventListener{
        public:
        ToTopButtonListener(ControlLayer* layer)
          :controlLayer(layer){}
          virtual ~ToTopButtonListener(){}

          virtual bool handle(const Event* e){
            controlLayer->workLayer->adjustToTop();
            return true;
          }
        private:
          ControlLayer* controlLayer;
      };
      /**
       * 控制层操作按钮监听器（移动选中元素到底层）
       */
      class ToBottomButtonListener : public EventListener{
        public:
        ToBottomButtonListener(ControlLayer* layer)
          :controlLayer(layer){}
          virtual ~ToBottomButtonListener(){}

          virtual bool handle(const Event* e){
            controlLayer->workLayer->adjustToBottom();
            return true;
          }
        private:
          ControlLayer* controlLayer;
      };

      /**
       * 控制层操作按钮监听器（上移一层选中元素）
       */
      class ToUpButtonListener : public EventListener{
        public:
        ToUpButtonListener(ControlLayer* layer)
          :controlLayer(layer){}
          virtual ~ToUpButtonListener(){}

          virtual bool handle(const Event* e){
            controlLayer->workLayer->adjustToUp();
            return true;
          }
        private:
          ControlLayer* controlLayer;
      };

      /**
       * 控制层操作按钮监听器（下移一层选中元素）
       */
      class ToNextButtonListener : public EventListener{
        public:
        ToNextButtonListener(ControlLayer* layer)
          :controlLayer(layer){}
          virtual ~ToNextButtonListener(){}

          virtual bool handle(const Event* e){
            controlLayer->workLayer->adjustToNext();
            return true;
          }
        private:
          ControlLayer* controlLayer;
      };

      /**
       * 控制层操作按钮监听器（组合）
       */
      class MergeButtonListener : public EventListener{
        public:
          MergeButtonListener(ControlLayer* layer)
          :controlLayer(layer){}
          virtual ~MergeButtonListener(){}

          virtual bool handle(const Event* e){
            controlLayer->workLayer->merge();
            return true;
          }
        private:
          ControlLayer* controlLayer;
      };

      /**
       * 控制层操作按钮监听器（取消组合）
       */
      class UnMergeButtonListener : public EventListener{
        public:
          UnMergeButtonListener(ControlLayer* layer)
          :controlLayer(layer){}
          virtual ~UnMergeButtonListener(){}

          virtual bool handle(const Event* e){
            controlLayer->workLayer->unmerge();
            return true;
          }
        private:
          ControlLayer* controlLayer;
      };

      private:
        real topMargins;
        //所有工具按钮
        hash_map<int, SimpleButton*> buttons;
        //工作层
        WorkLayer* workLayer;
        //控制层操作按钮监听器
        ToTopButtonListener toTopBtnLstner;
        ToBottomButtonListener toBottomBtnLstner;
        ToUpButtonListener toUpBtnLstner;
        ToNextButtonListener toNextBtnLstner;
        MergeButtonListener mergeBtnLstner;
        UnMergeButtonListener unMergeBtnLstner;


  };
}
#endif /* CONTROLLAYER_H_ */
